<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="按订单号编号">
              <a-input placeholder="请输入订单号" v-model="queryParam.id"></a-input>
            </a-form-item>
          </a-col>
          <template>
            <a-col :xl="4" :lg="7" :md="8" :sm="24">
              <a-form-item label="按订单状态">
                <a-select v-model="queryParam.status" placeholder="请输入订单状态">
                  <a-select-option value="-1">请选择</a-select-option>
                  <a-select-option :value="0">待接诊</a-select-option>
                  <a-select-option :value="1">进行中</a-select-option>
                  <a-select-option :value="2">确认中</a-select-option>
                  <a-select-option :value="3">结算中</a-select-option>
                  <a-select-option :value="4">已结算</a-select-option>
                  <a-select-option :value="5">退款</a-select-option>
                  <a-select-option :value="6">关闭</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="按用户名称">
              <a-input placeholder="请输入用户名称" v-model="queryParam.userName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="按医生名称">
              <a-input placeholder="请输入医生名称" v-model="queryParam.doctorName"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('order')">导出</a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        <span style="float:right;">
          <a @click="loadData()"><a-icon type="sync" />刷新</a>
        </span>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :loading="loading"
        :pagination="ipagination"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record" >
<!--          <a-button style="margin-left: 8px;color: #050404;background-color: #00DB00">-->
<!--             <router-link :to="`/OrderInfo/${record.id}`">查看详情111</router-link>-->
<!--          </a-button>-->
<!--          <a-divider type="vertical" />-->
            <a-button class="ant-dropdown-link">
                  <a @click="handleOrderModal(record)">查看详情</a>
            </a-button>


          <span v-if="record.status == 3">
             <a-button @click="handleOrder(record)"  style="margin-left: 8px;background-color: #0e9ddb;color:white;">确定</a-button>
          </span>
          <span v-if="record.status == 4"></span>

          <a-dropdown style="margin-left: 8px;background-color: #f3f0f0">
            <a-button class="ant-dropdown-link">平台管理<a-icon type="down" /></a-button>
            <a-menu slot="overlay">
              <a-menu-item>
                 <a>
                  <router-link :to="`/settlementIndex/${record.id}`">结算管理</router-link>
                 </a>
              </a-menu-item>
              <a-menu-item>
                 <a>
                  <router-link :to="`/settlementData/${record.id}`">结算详情</router-link>
                 </a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
     <order-info-modal ref="orderInfoModal"></order-info-modal>
    <order-modal ref="modalForm" @ok="modalFormOk"></order-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import OrderModal from './OrderModal'
  // import SettlementData from './settlement/SettlementData'
  import { httpAction, postAction,getAction } from '@api/manage'
  import  OrderInfoModal from './modules/OrderInfoModal'



  export default {
    name: 'OrderList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      OrderModal,
      OrderInfoModal

    },
    data () {
      return {
        description: 'order管理页面',
        // 表头
        columns: [
          {
            title:'订单编号',
            align:"center",
            dataIndex: 'id'
          },
          {
            title:'创建时间',
            align:"center",
            dataIndex: 'createTime'
          },
          {
            title:'订单类型',
            align:"center",
            dataIndex: 'shopType',
            customRender:function (res) {
              let type;
              if(res == 1){
                type = "图文问诊";
              }else if(res == 2){
                type = "视频问诊";
              }
              return type;
            }
          },
          {
            title:'订单状态',
            align:"center",
            dataIndex: 'status',
            customRender:function (res) {
              let status='';
              if(res == 0){
                status = "待接诊";
              }else if(res == 1){
                status = "进行中";
              }else if(res == 2){
                status = "确认中";
              } else if(res == 3){
                status = "结算中";
              } else if(res == 4){
                status = "已结算";
              }else if(res == 5){
                status = "退款";
              }else if(res == 6){
                status = "关闭";
              }
              return status;
            }
          },
          {
            title:'订单用户',
            align:"center",
            dataIndex: 'userName'
          },
          {
            title:'订单医生',
            align:"center",
            dataIndex: 'doctorName',
          },
          {
            title:'订单金额',
            align:"center",
            dataIndex: 'amount',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/order/order/list",
          delete: "/order/order/delete",
          info: "/settlement/settlement/setMoney",
          deleteBatch: "/order/order/deleteBatch",
          exportXlsUrl: "/order/order/exportXls",
          importExcelUrl: "order/order/importExcel",

        },
        dictOptions:{},
      }
    },
    created() {
      this.handleOrder(this.$route.params.id );

    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },

      handleOrder(record){

        let param = { };
        param.id =record.id;

        postAction(this.url.info,param).then(res=>{

          if(res){
            this.$message.success(res.message);
            this.reload()
          }else{
            this.$message.warning(res.message)
            this.reload()
          }

        })

      },
      handleOrderModal(record){
        this.$refs.orderInfoModal.showOrderInfo(record)
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>